package com.weetop.cfw.mine.adapter

import android.widget.TextView
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.SpanUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.coorchice.library.SuperTextView
import com.weetop.cfw.R
import com.weetop.cfw.bean.MyCoursesBean
import com.weetop.cfw.constants.UrlConstants

class CoursesPurchasedByUsersListAdapter(layoutId: Int, dataList: List<MyCoursesBean.DataBean>) :
    BaseQuickAdapter<MyCoursesBean.DataBean, BaseViewHolder>(layoutId, dataList) {
    override fun convert(helper: BaseViewHolder, item: MyCoursesBean.DataBean?) {
        val imageCourseLogo = helper.getView<SuperTextView>(R.id.imageCourseLogo)
        var textCourseOrderPrice = helper.getView<TextView>(R.id.textCourseOrderPrice)
        imageCourseLogo.setUrlImage("${UrlConstants.baseUrl}${item?.imgurl}")
        helper.setText(R.id.textCourseOrderTime, item?.orderdate)
            .setText(R.id.textCourseOrderNo, "订单号：${item?.orderid}")
            .setText(R.id.textCourseTeacherName, item?.author)
            .setText(R.id.textCoursePlayNumber, item?.playnum)
            .setText(R.id.textCourseTitle, item?.title)
            .addOnClickListener(R.id.btnCancelCourseOrder, R.id.btnAtOncePay)
        if (item?.statusX == 0) {
            helper.setText(R.id.textCourseOrderStatus, "待支付")
                .setGone(R.id.textCourseOrderPrice, true)
                .setGone(R.id.btnCancelCourseOrder, true)
                .setGone(R.id.btnAtOncePay, true)
        } else if (item?.statusX == 1) {
            helper.setText(R.id.textCourseOrderStatus, "支付成功")
                .setGone(R.id.textCourseOrderPrice, false)
                .setGone(R.id.btnCancelCourseOrder, false)
                .setGone(R.id.btnAtOncePay, false)
        } else {
            helper.setText(R.id.textCourseOrderStatus, "已取消")
                .setGone(R.id.textCourseOrderPrice, false)
                .setGone(R.id.btnCancelCourseOrder, false)
                .setGone(R.id.btnAtOncePay, false)
        }
        SpanUtils.with(textCourseOrderPrice).append("￥")
            .setForegroundColor(ColorUtils.string2Int("#F42626")).setFontSize(12, true)
            .append(item?.sprice!!)
            .setForegroundColor(ColorUtils.string2Int("#F42626")).setFontSize(18, true).setBold()
            .create()
    }
}